package just.stuff.morsels.ui.label;


import java.util.List;

import just.stuff.morsels.MorselApplication;
import just.stuff.morsels.objects.Morsel;
import just.stuff.morsels.ui.BasePage;
import just.stuff.morsels.ui.assist.OfferAssistanceLink;
import just.stuff.morsels.ui.morsel.MorselList;
import just.stuff.morsels.ui.morsel.MorselPage;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;

public class LabelPage extends BasePage  {

	public static final String PARAM_LABEL = "label";

	public LabelPage( PageParameters params ) {
		this( params.get( PARAM_LABEL).toString() );
	}
	
	public LabelPage( final String label ) {
		add( new Label( PARAM_LABEL, label ) );
		final List<Morsel> morsels = MorselApplication.dataSource().morsels( label );
		add( new Link<Void>( "delete" ) {
			@Override
			public void onClick() {
				MorselApplication.dataSource().deleteLabel( label );
				setResponsePage( MorselPage.class );
			}
			
			@Override
			public boolean isVisible() {
				return morsels == null  || morsels.isEmpty(); 
			}
			
		});
		add( new MorselList( "list", Model.ofList( morsels )));
		add( new LabelGraphPanel( "graph", label));

		add( new OfferAssistanceLink( "assistanceLink", label ) );
		
		
	}
	
	
}
